<?php
namespace app\admin\controller;
use think\facade\Db;
use think\facade\Request;

class Danqun extends  Base
{

    //友情链接列表
    public function index()
    {
        error_reporting(E_ERROR | E_WARNING | E_PARSE);
        $loginAdmin=session('adminAccount'); 
      
    $turl="http://".$_SERVER['SERVER_NAME']."/index/qun?uid=".$loginAdmin['id'];
    $config=Db::name('danqun')->where('id',1)->find();
  
    $name=$datas['name']=(array)json_decode($config['name']);
    $img=$datas['img']=(array)json_decode($config['img']);
    $member=$datas['member']=(array)json_decode($config['member']);
    $jianjie=$datas['overview']=(array)json_decode($config['overview']);
   if(request()->isPost()){
        $data=request()->post(); 
        $datas['name']=json_encode($data);
     
        $res=Db::name('danqun')->where('id',1)->update($datas);
         if($res){
            return alert('操作成功！','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         }
   }

      return view('',[
       'turl'=>$turl,
       'name'=>$name,
       'img'=>$img,
       'member'=>$member,
       'jianjie'=>$jianjie,
       'yemian'=>1,
        ]);

    }

    /*添加*/
    public function qunmentou(){
    $loginAdmin=session('adminAccount'); 
    $turl="http://".$_SERVER['SERVER_NAME']."/index/qun?uid=".$loginAdmin['id'];
    $config=Db::name('danqun')->find(1);
    $img=$datas['img']=(array)json_decode($config['img']);
      if(request()->isPost()){
        $data=request()->post();
     
        $datas['img']=json_encode($data);
     
        $res=Db::name('danqun')->where('id',1)->update($datas);
         if($res){
            return alert('操作成功！','qunmentou',6,3);
         }else{
            return alert('操作失败！','qunmentou',5,3);
         }
         
   }
   
      return view('',[
       'img'=>$img,
        'yemian'=>2,
        ]);
    }
      public function qunchengyuantuxiang(){
          $erji=input('erji');
          if($erji == null){
             $erji=1; 
          }
             $loginAdmin=session('adminAccount'); 
    $turl="http://".$_SERVER['SERVER_NAME']."/index/qun?uid=".$loginAdmin['id'];
    $config=Db::name('danqun')->where('id',1)->find();
    $quntouxianglist=Db::name('danqunlist')->where('type','1')->where('uid',0)->paginate([
              'list_rows'=> 20,//每页数量
              'query' => request()->param(),
              ]);
    $member=$datas['member']=(array)json_decode($config['member']);
      if(request()->isPost()){
        $data=request()->post();
     
        $datas['member']=json_encode($data);
     
        $res=Db::name('danqun')->where('id', 1)->update($datas);
         if($res){
            return alert('操作成功！','qunchengyuantuxiang',6,3);
         }else{
            return alert('操作失败！','qunchengyuantuxiang',5,3);
         }
         
   }
   
    return view('',[
       'member'=>$member,
        'yemian'=>3,
         'erji'=>$erji,
         'toulist'=>$quntouxianglist,
        ]);
 
    }
      public function quntouxiangadd(){
    	if(request()->isPost()) {

			// 入库的逻辑
             $loginAdmin=session('adminAccount'); 
			$data = input('post.');
			unset($data['file']);
			 $data['type']="1";
             $data['uid']=0;
			$res = Db::name('danqunlist')->insert($data);

			if($res){
				return alert('操作成功！','qunchengyuantuxiang?erji=2',6,3);
			 }else{
				return alert('操作失败！','qunchengyuantuxiang?erji=2',5,3);
			 }

		}
		 return view('',[
       
        ]);

	}

     public function jianjie(){
    $loginAdmin=session('adminAccount'); 
    $turl="http://".$_SERVER['SERVER_NAME']."/index/qun?uid=".$loginAdmin['id'];
    $config=Db::name('danqun')->find(1);
    $jianjie=$datas['overview']=(array)json_decode($config['overview']);
      if(request()->isPost()){
        $data=request()->post();
     
        $datas['overview']=json_encode($data);
     
        $res=Db::name('danqun')->where('id', 1)->update($datas);
         if($res){
            return alert('操作成功！','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         }
   }
    return view('',[
       'jianjie'=>$jianjie,
        'yemian'=>4,
        ]);
    }
     public function qunyouxiu(){
            $erji=input('erji');
          if($erji == null){
             $erji=1; 
          }
    $loginAdmin=session('adminAccount'); 
    $turl="http://".$_SERVER['SERVER_NAME']."/index/qun?uid=".$loginAdmin['id'];
    $config=Db::name('danqun')->find(1);
    $GroupFriendsShow=$datas['GroupFriendsShow']=(array)json_decode($config['GroupFriendsShow']);
      $qunyouxiu=Db::name('danqunlist')->where('type','2')->where('uid',0)->paginate([
              'list_rows'=> 20,//每页数量
              'query' => request()->param(),
              ]);
      if(request()->isPost()){
        $data=request()->post();
     
        $datas['GroupFriendsShow']=json_encode($data);
     
        $res=Db::name('danqun')->where('id', 1)->update($datas);
         if($res){
            return alert('操作成功！','qunyouxiu',6,3);
         }else{
            return alert('操作失败！','qunyouxiu',5,3);
         }
   }
    return view('',[
       'GroupFriendsShow'=>$GroupFriendsShow,
        'yemian'=>5,
         'erji'=>$erji,
          'qunyou'=>$qunyouxiu,
        ]);
    }
     public function qunyouxiuadd(){
    	if(request()->isPost()) {

			// 入库的逻辑
             $loginAdmin=session('adminAccount'); 
			$data = input('post.');
			unset($data['file']);
			 $data['type']="2";
             $data['uid']=0;
			$res = Db::name('danqunlist')->insert($data);

			if($res){
				return alert('操作成功！','qunyouxiu?erji=2',6,3);
			 }else{
				return alert('操作失败！','qunyouxiu?erji=2',5,3);
			 }

		}
		 return view('',[
       
        ]);

	}

     public function ruqunfuli(){
             $erji=input('erji');
          if($erji == null){
             $erji=1; 
          }
    $loginAdmin=session('adminAccount'); 
    $turl="http://".$_SERVER['SERVER_NAME']."/index/qun?uid=".$loginAdmin['id'];
    $config=Db::name('danqun')->find(1);
    $GroupBenefits=$datas['GroupBenefits']=(array)json_decode($config['GroupBenefits']);
      $fuli=Db::name('danqunlist')->where('type','3')->where('uid',0)->paginate([
              'list_rows'=> 20,//每页数量
              'query' => request()->param(),
              ]);
      if(request()->isPost()){
        $data=request()->post();
     
        $datas['GroupBenefits']=json_encode($data);
     
        $res=Db::name('danqun')->where('id', 1)->update($datas);
         if($res){
            return alert('操作成功！','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         }
   }
    return view('',[
       'GroupBenefits'=>$GroupBenefits,
        'yemian'=>6,
          'erji'=>$erji,
          'fuli'=>$fuli,
        ]);
    }
     public function fuliadd(){
    	if(request()->isPost()) {

			// 入库的逻辑
             $loginAdmin=session('adminAccount'); 
			$data = input('post.');
			unset($data['file']);
			 $data['type']="3";
             $data['uid']=0;
			$res = Db::name('danqunlist')->insert($data);

			if($res){
				return alert('操作成功！','ruqunfuli?erji=2',6,3);
			 }else{
				return alert('操作失败！','ruqunfuli?erji=2',5,3);
			 }

		}
		 return view('',[
       
        ]);

	}
      public function changjianwenti(){
              $erji=input('erji');
          if($erji == null){
             $erji=1; 
          }
    $loginAdmin=session('adminAccount'); 
    $turl="http://".$_SERVER['SERVER_NAME']."/index/qun?uid=".$loginAdmin['id'];
    $config=Db::name('danqun')->find(1);
     $wenda=Db::name('danqunlist')->where('type','4')->where('uid',0)->paginate([
              'list_rows'=> 20,//每页数量
              'query' => request()->param(),
              ]);
    $ask=$datas['ask']=(array)json_decode($config['ask']);
      if(request()->isPost()){
        $data=request()->post();
     
        $datas['ask']=json_encode($data);
     
        $res=Db::name('danqun')->where('id', 1)->update($datas);
         if($res){
            return alert('操作成功！','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         }
   }
    return view('',[
       'ask'=>$ask,
        'yemian'=>7,
         'erji'=>$erji,
          'wenda'=>$wenda,
        ]);
    }
     public function wentiadd(){
    	if(request()->isPost()) {

			// 入库的逻辑
             $loginAdmin=session('adminAccount'); 
			$data = input('post.');
			unset($data['file']);
			 $data['type']="4";
             $data['uid']=0;
			$res = Db::name('danqunlist')->insert($data);

			if($res){
				return alert('操作成功！','changjianwenti?erji=2',6,3);
			 }else{
				return alert('操作失败！','changjianwenti?erji=2',5,3);
			 }

		}
		 return view('',[
       
        ]);

	}
     public function jingxuanpinglun(){
              $erji=input('erji');
          if($erji == null){
             $erji=1; 
          }
    $loginAdmin=session('adminAccount'); 
    $turl="http://".$_SERVER['SERVER_NAME']."/index/qun?uid=".$loginAdmin['id'];
    $config=Db::name('danqun')->find(1);
    $interlocution=$datas['interlocution']=(array)json_decode($config['interlocution']);
      $pinglun=Db::name('danqunlist')->where('type','5')->where('uid',0)->paginate([
              'list_rows'=> 20,//每页数量
              'query' => request()->param(),
              ]);
      if(request()->isPost()){
        $data=request()->post();
     
        $datas['interlocution']=json_encode($data);
     
        $res=Db::name('danqun')->where('id', 1)->update($datas);
         if($res){
            return alert('操作成功！','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         }
   }
    return view('',[
       'interlocution'=>$interlocution,
        'yemian'=>8,
         'erji'=>$erji,
          'pinglun'=>$pinglun,
        ]);
    }
      public function pinglunadd(){
    	if(request()->isPost()) {

			// 入库的逻辑
             $loginAdmin=session('adminAccount'); 
			$data = input('post.');
			unset($data['file']);
			 $data['type']="5";
             $data['uid']=0;
			$res = Db::name('danqunlist')->insert($data);

			if($res){
				return alert('操作成功！','jingxuanpinglun?erji=2',6,3);
			 }else{
				return alert('操作失败！','jingxuanpinglun?erji=2',5,3);
			 }

		}
		 return view('',[
       
        ]);

	}
     public function yuedudianzanshu(){
    $loginAdmin=session('adminAccount'); 
    $turl="http://".$_SERVER['SERVER_NAME']."/index/qun?uid=".$loginAdmin['id'];
    $config=Db::name('danqun')->find(1);
    $yuedudianzanshu=$datas['yuedudianzanshu']=(array)json_decode($config['yuedudianzanshu']);
      if(request()->isPost()){
        $data=request()->post();
     
        $datas['yuedudianzanshu']=json_encode($data);
     
        $res=Db::name('danqun')->where('id', 1)->update($datas);
         if($res){
            return alert('操作成功！','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         }
   }
    return view('',[
       'yuedudianzanshu'=>$yuedudianzanshu,
        'yemian'=>9,
        ]);
    }
      public function lianxikefu(){
    $loginAdmin=session('adminAccount'); 
    $turl="http://".$_SERVER['SERVER_NAME']."/index/qun?uid=".$loginAdmin['id'];
    $config=Db::name('danqun')->find(1);
    $lianxikefu=$datas['lianxikefu']=(array)json_decode($config['lianxikefu']);
      if(request()->isPost()){
        $data=request()->post();
     
        $datas['lianxikefu']=json_encode($data);
     
        $res=Db::name('danqun')->where('id', 1)->update($datas);
         if($res){
            return alert('操作成功！','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         }
   }
    return view('',[
       'lianxikefu'=>$lianxikefu,
        'yemian'=>10,
        ]);
    }
    

      public function listdel()
    {
       $id=input('id');//助手函数

      $res=Db::name('danqunlist')->delete($id);
      if($res){
            return alert('删除成功!','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         } 
    }
      public function paid(){
          	// 入库的逻辑
        $loginAdmin=session('adminAccount'); 
          $ress=Db::name('paid')->where('id',1)->find();
         if(request()->isPost()){
             
         $data=request()->post();
         $data['uid']=0;
         $res=Db::name('paid')->where('id',1)->update($data);
         if($res){
            return alert('操作成功！','paid',6,3);
         }else{
            return alert('操作失败！','paid',5,3);
         }
       } 
       
       return view('',[
         'paid'=>$ress,
        ]);

    }
    
}
